##############################################################
#Figure G2: Hurricane Proximity and Incumbent Victory in US House
##############################################################

dem <- read.dta13("./temp/figg2adata.dta")
rep <- read.dta13("./temp/figg2bdata.dta")

newdem <- dem %>% 
  gather(variable, value, -var)%>%
  spread(var, value)

newdem$id <- c(5,4,3,2,6,1)


newrep <- rep %>% 
  gather(variable, value, -var)%>%
  spread(var, value)

newrep$id <- c(5,4,3,2,6,1)


gdem<- ggplot() + 
  geom_pointrange(data=newdem, mapping=aes(x=id, y=coef, ymin=ci_upper, 
                                           ymax=ci_lower), color="blue", size=1.2, fatten=2, fill="blue", shape=21) +
  ylim(-.4,.4) +
  scale_x_discrete(limit=c("1", "2", "3", "4", "5", "6"), labels= c("[500,30)", "[400,30)", "[300,30)", "[200,30)", "[100,30)", "[50,30)")) + 
  xlab("Distance Band")  + ylab("Probability of Incumbent Victory") +
  geom_hline(yintercept=0, col="grey60", lwd=1, lty="dashed", alpha=.6)  + 
  theme_bw() + 
  theme(plot.title =element_text(hjust = .5, face="bold", size=15, colour = "black"),
        axis.text=element_text(size=12), 
        axis.title = element_text(size=15),
        panel.grid.minor = element_blank(),
        panel.grid.major.y = element_blank()) 
gdem


grep<- ggplot() + 
  geom_pointrange(data=newrep, mapping=aes(x=id, y=coef, ymin=ci_upper, 
                                           ymax=ci_lower), color="red", size=1.2, fatten=2, fill="red", shape=21) +
  ylim(-.4,.4) +
  scale_x_discrete(limit=c("1", "2", "3", "4", "5", "6"), labels= c("[500,30)", "[400,30)", "[300,30)", "[200,30)", "[100,30)", "[50,30)")) + 
  xlab("Distance Band")  + ylab("Probability of Incumbent Victory") +
  geom_hline(yintercept=0, col="grey60", lwd=1, lty="dashed", alpha=.6)  + 
  theme_bw() + 
  theme(plot.title =element_text(hjust = .5, face="bold", size=15, colour = "black"),
        axis.text=element_text(size=12), 
        axis.title = element_text(size=15),
        panel.grid.minor = element_blank(),
        panel.grid.major.y = element_blank()) 
grep

ggarrange(gdem, grep)
ggsave(file="./figures/figg2.pdf")